<script setup>
import { queryOverviewApi } from '@/api/home'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 概览数据
const overviewData = ref({
  clueTotal: 0,
  clueWaitAllot: 0,
  clueWaitFollow: 0,
  clueFollowing: 0,
  clueFalse: 0,
  clueConvertBusiness: 0,
  businessTotal: 0,
  businessWaitAllot: 0,
  businessWaitFollow: 0,
  businessFollowing: 0,
  businessFalse: 0,
  businessConvertCustomer: 0
})

// 获取概览数据
const getOverviewData = async () => {
  try {
    const result = await queryOverviewApi()
    if (result.code === 1) {
      overviewData.value = result.data
    }
  } catch (error) {
    console.error('获取概览数据失败:', error)
  }
}

// 快捷操作跳转
const handleQuickAction = (route) => {
  router.push(route)
}

// 页面加载时执行
onMounted(() => {
  getOverviewData()
})
</script>

<template>
  <div class="home-container">
    <!-- 欢迎信息 -->
    <div class="welcome-section">
      <h1 class="welcome-title">欢迎进入轻客管家系统</h1>
    </div>

    <!-- 概览区域 -->
    <div class="overview-section">
      <!-- 线索概览 -->
      <div class="overview-card">
        <h2 class="card-title">线索概览</h2>
        <div class="overview-grid">
          <div class="overview-item">
            <div class="item-title">总线索数</div>
            <div class="item-value">{{ overviewData.clueTotal }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">待分配线索数</div>
            <div class="item-value">{{ overviewData.clueWaitAllot }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">待跟进线索数</div>
            <div class="item-value">{{ overviewData.clueWaitFollow }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">跟进中线索数</div>
            <div class="item-value">{{ overviewData.clueFollowing }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">伪线索数</div>
            <div class="item-value">{{ overviewData.clueFalse }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">转商机线索数</div>
            <div class="item-value">{{ overviewData.clueConvertBusiness }}</div>
          </div>
        </div>
      </div>

      <!-- 商机概览 -->
      <div class="overview-card">
        <h2 class="card-title">商机概览</h2>
        <div class="overview-grid">
          <div class="overview-item">
            <div class="item-title">总商机数</div>
            <div class="item-value">{{ overviewData.businessTotal }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">待分配商机数</div>
            <div class="item-value">{{ overviewData.businessWaitAllot }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">待跟进商机数</div>
            <div class="item-value">{{ overviewData.businessWaitFollow }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">跟进中商机数</div>
            <div class="item-value">{{ overviewData.businessFollowing }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">回收商机数</div>
            <div class="item-value">{{ overviewData.businessFalse }}</div>
          </div>
          <div class="overview-item">
            <div class="item-title">转客户商机数</div>
            <div class="item-value">{{ overviewData.businessConvertCustomer }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 管理模块区域 -->
    <div class="modules-section">
      <!-- <h2 class="section-title">管理模块</h2> -->
      <div class="modules-grid">
        <!-- 课程管理 -->
        <div class="module-card" @click="handleQuickAction('/resource/course')">
          <div class="module-icon">
            <el-icon size="32"><Reading /></el-icon>
          </div>
          <div class="module-content">
            <h3 class="module-title">课程管理</h3>
            <p class="module-subtitle">课程信息维护</p>
          </div>
        </div>

        <!-- 活动管理 -->
        <div class="module-card" @click="handleQuickAction('/resource/activity')">
          <div class="module-icon">
            <el-icon size="32"><Calendar /></el-icon>
          </div>
          <div class="module-content">
            <h3 class="module-title">活动管理</h3>
            <p class="module-subtitle">营销活动管理</p>
          </div>
        </div>

        <!-- 线索管理 -->
        <div class="module-card" @click="handleQuickAction('/clue/list')">
          <div class="module-icon">
            <el-icon size="32"><User /></el-icon>
          </div>
          <div class="module-content">
            <h3 class="module-title">线索管理</h3>
            <p class="module-subtitle">潜在客户追踪</p>
          </div>
        </div>

        <!-- 商机管理 -->
        <div class="module-card" @click="handleQuickAction('/business/list')">
          <div class="module-icon">
            <el-icon size="32"><Opportunity /></el-icon>
          </div>
          <div class="module-content">
            <h3 class="module-title">商机管理</h3>
            <p class="module-subtitle">销售机会管理</p>
          </div>
        </div>

        <!-- 客户管理 -->
        <div class="module-card" @click="handleQuickAction('/customer')">
          <div class="module-icon">
            <el-icon size="32"><UserFilled /></el-icon>
          </div>
          <div class="module-content">
            <h3 class="module-title">客户管理</h3>
            <p class="module-subtitle">客户信息维护</p>
          </div>
        </div>

        <!-- 日志统计 -->
        <div class="module-card" @click="handleQuickAction('/system/log')">
          <div class="module-icon">
            <el-icon size="32"><Document /></el-icon>
          </div>
          <div class="module-content">
            <h3 class="module-title">日志统计</h3>
            <p class="module-subtitle">系统操作日志</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.home-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

/* 欢迎区域 */
.welcome-section {
  text-align: center;
  margin-bottom: 30px;
}

.welcome-title {
  font-size: 60px;
  font-weight: 500;
  color: #2607b1;
  margin: 0;
  padding: 10px 0;
  font-family: "楷体", "KaiTi", serif;
}

/* 概览区域 */
.overview-section {
  display: flex;
  gap: 20px;
  margin-bottom: 40px;
}

.overview-card {
  flex: 1;
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.card-title {
  font-size: 50px;
  font-weight: 600;
  color: #08b34f;
  margin: 0 0 20px 0;
  text-align: center;
  font-family: "楷体", "KaiTi", serif;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.overview-item {
  text-align: center;
  padding: 16px;
  background-color: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e9ecef;
}

.item-title {
  font-size: 14px;
  color: #606266;
  margin-bottom: 8px;
  line-height: 1.4;
  font-family: "楷体", "KaiTi", serif;
}

.item-value {
  font-size: 28px;
  font-weight: 600;
  color: #409eff;
}

/* 管理模块区域 */
.modules-section {
  background-color: #fff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 24px 0;
  text-align: center;
  font-family: "楷体", "KaiTi", serif;
}

.modules-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.module-card {
  display: flex;
  align-items: center;
  padding: 24px;
  background-color: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
  cursor: pointer;
  transition: all 0.3s ease;
}

.module-card:hover {
  background-color: #e6f7ff;
  border-color: #409eff;
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(64, 158, 255, 0.2);
}

.module-icon {
  margin-right: 16px;
  color: #409eff;
}

.module-content {
  flex: 1;
}

.module-title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 6px 0;
  font-family: "楷体", "KaiTi", serif;
}

.module-subtitle {
  font-size: 18px;
  color: #909399;
  margin: 0;
  line-height: 1.4;
  font-family: "楷体", "KaiTi", serif;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .overview-section {
    flex-direction: column;
  }
  
  .modules-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .modules-grid {
    grid-template-columns: 1fr;
  }
  
  .welcome-title {
    font-size: 28px;
  }
  
  .card-title {
    font-size: 18px;
  }
  
  .module-title {
    font-size: 16px;
  }
  
  .item-value {
    font-size: 24px;
  }
}
</style>
